package com.yuexun.beilunpatient.ui.family.presenter.impl;

import com.yuexun.beilunpatient.base.BaseEntity;
import com.yuexun.beilunpatient.ui.family.bean.KinsfolkBean;
import com.yuexun.beilunpatient.ui.family.model.IFamilyModel;
import com.yuexun.beilunpatient.ui.family.presenter.IFamilyListPresenter;
import com.yuexun.beilunpatient.ui.family.ui.view.IFamilyListView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/11/6.
 */
public class FamilyListPresenter implements IFamilyListPresenter {

    private IFamilyListView view;
    private IFamilyModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public FamilyListPresenter(IFamilyModel model, IFamilyListView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getAppoinmentFamilyNum(Map<String, String> praise) {
        model.getAppoinmentFamilyNum(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<KinsfolkBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取亲情会员信息失败:");
                    }

                    @Override
                    public void onNext(BaseEntity<KinsfolkBean> baseEntity) {
                        view.getAppoinmentFamilyNum(baseEntity);
                    }
                });
    }

    @Override
    public void deletePatientRelative(Map<String, String> praise) {
        model.deletePatientRelative(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<String>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("删除亲属号失败:");
                    }

                    @Override
                    public void onNext(BaseEntity<String> baseEntity) {
                        view.deletePatientRelative(baseEntity);
                    }
                });
    }
}
